<!--
 * @Author: xuwejie 1529315455@qq.com
 * @Date: 2023-08-28 11:38:43
 * @LastEditors: xuwejie 1529315455@qq.com
 * @LastEditTime: 2023-08-28 14:17:40
 * @FilePath: \cdj-jyt_school-vue\src\views\shop\service.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="page">
      <Editor
        api-key="vl7byj8kh7hyvvi6o7137s7khcpfsp762987dlnbcd93u37a"
        v-model="content"
        :init="init"
      ></Editor>
      <div class="bottom">
        <el-button
          class="btn"
          type="primary"
          @click="submit()"
          v-repeatClick
        >保存</el-button>
      </div>
  </div>
</template>

<script>
import Editor from "@tinymce/tinymce-vue";
import init from "./init";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { partnerNotice_index,partnerNotice_save } from "@/api/shop/shop";

export default {
  data(){
    return{
      content:'',
      // 富文本
      init,
    }
  },
  created(){
    this.getData()
  },
  methods:{
    getData(){
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name,{type:2})) +
              apiUrl().appsecret
          ),
        },
        {type:2},
        apiUrl().name,
      );
      partnerNotice_index(data).then((res) => {
        if (res.errcode == 0) {
          this.content = res.data.content;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    submit(){
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name,{type:3,content:this.content})) +
              apiUrl().appsecret
          ),
        },
        {type:3,content:this.content},
        apiUrl().name,
      );
      partnerNotice_save(data).then((res) => {
        if (res.errcode == 0) {
          this.$message.success('保存成功');
        } else {
          this.$message.error(res.errmsg);
        }
      });
    }
  },
  components: {
    Editor,
  },
}
</script>

<style lang="scss" scoped>
.page{
  width:100%;
  height:100vh;
  .bottom{
    background:#fff;
    box-shadow: 10px 10px 10px #eee;
    width:100%;
    height:50px;
    display: flex;
    align-items: center;
    padding:40px 30px;
    .btn{
      width:120px;
    }
  }
}
</style>